<!DOCTYPE html>
<html>
<head>
    <meta charset="utf-8">
    <meta name="viewport" content="width=device-width, initial-scale=1, maximum-scale=1">
    <title>LcsdAdmin</title>
    <link rel="stylesheet" href="{{URL::asset('/layui/css/layui.css')}}">
</head>
<body class="layui-layout-body" style="padding: 10px">
    <form class="layui-form">
        <div class="layui-layout layui-layout-admin">


            <!-- 搜索内容区域 -->
            <div class="layui-form-item">
                <div class="layui-inline">
                    <label class="layui-form-label">选择框</label>
                    <div class="layui-input-inline">
                        <select name="pid" lay-verify="required" lay-search="">
                            <option value="0">直接选择或搜索选择</option>
                            <option value="0">无</option>
                            @foreach ($category as $v)
                                <option value="{{$v['id']}}">{{$v['name']}}</option>
                            @endforeach
                        </select>
                    </div>
                </div>
            </div>
            <!-- 结束 -->


            <!-- 内容主体区域 -->
            <div class="layui-form-item" style="padding: 10px">
                <fieldset class="layui-elem-field">
                    <legend>请输入分类名</legend>
                    <div class="layui-field-box">
                        <div class="layui-input-block" style="width: 50%;margin-left: 13px;">
                            <input type="text" name="name" lay-verify="required" lay-reqtext="分类名是必填项，岂能为空？" placeholder="{{$ca['name']}}" autocomplete="off" class="layui-input">
                        </div>
                    </div>
                </fieldset>
            </div>
            @if ($ca['pid'] != 0)
            <div class="layui-form-item" style="padding: 10px">
                <fieldset class="layui-elem-field">
                    <legend>请输入链接路径</legend>
                    <div class="layui-field-box">
                        <div class="layui-input-block" style="width: 50%;margin-left: 13px;">
                            <input type="text" name="config" lay-verify="required" lay-reqtext="分类名是必填项，岂能为空？" placeholder="{{$ca['config']}}" autocomplete="off" class="layui-input">
                        </div>
                    </div>
                </fieldset>
            </div>
            @endif
            <!-- 结束 -->

            <!-- 按钮区域 -->
            <div class="layui-form-item">
                <div class="layui-input-block">
                    <button type="submit" class="layui-btn" lay-submit="" lay-filter="demo1">提交</button>
                    <button type="reset" class="layui-btn layui-btn-primary">重置</button>
                </div>
            </div>
            <!-- 结束 -->
        </div>
    </form>
    <script src="{{URL::asset('/layui/layui.js')}}"></script>
    <script>
        var info;
        function child(d){
            info = JSON.parse(d);
        }
        layui.use(['layer','form'], function(){
            var $ = layui.$;
            var index = parent.layer.getFrameIndex(window.name); //获取窗口索引
            var url = "{{url('admin/menu/save')}}";
            $('.layui-btn').on('click', function(){
                var obj = {};
                obj.name = $('input[name=name]').val();
                obj.config = $('input[name=config]').val();
                obj.id = info.id;
                obj.pid = $("select[name=pid]").val();
                var detailDateStr = JSON.stringify(obj)
                $.ajax({
                    url:url,
                    type:'post',
                    data:{
                        'data':detailDateStr,
                        '_token':'{{csrf_token()}}',
                        'type':'2',
                    },
                    success:function(data){
                        layer.alert('成功');
                        parent.location.reload(); // 刷新父级页面
                        parent.layer.close(index); //关闭当前页面
                    },
                });
            });
        });
    </script>
</body>
</html>
